package jiang.Algorithm;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @ClassName JiTuTongLong
 * @Description: 鸡兔同笼算法
 * @Author jiangshitao
 * @Date 2023/2/5
 *
 * 看到狂飙里面高启盛算的很快，我来试试能不能写个代码实现一下
 */
public class JiTuTongLong {
    /**
     * 解题
     * @param head 头的数目
     * @param foot 脚的数目
     */
    public static void calculation(int head, int foot) {
        int ji = 0;
        int tuZi = 0;
        boolean flag = false;

        for (ji = 0; ji < head; ji++) {
            tuZi = head - ji;
            if (ji+tuZi == head && (ji * 2) + (tuZi * 4) == foot) {
                System.out.println(tuZi + "只兔子" + ji + "只鸡");
                flag = true;
                break;
            }
        }
        if (!flag) {
            System.out.println("题目出错了！");
        }
    }

    /**
     * 出题
     * @return 集合
     */
    public static List<Integer> generate() {
        List<Integer> list = new ArrayList<Integer>();
        Random random = new Random();
        int ji = random.nextInt(100) + 1;
        int tuZi = random.nextInt(100) + 1;
        int head = ji + tuZi;
        int foot = (ji * 2) + (tuZi * 4);
        list.add(head);
        list.add(foot);
        System.out.println(tuZi + "," + ji);
        return list;
    }

    public static void main(String[] args) {
        List<Integer> generate = generate();
        Integer head = generate.get(0);
        Integer foot = generate.get(1);
        System.out.println(head + "个头" + foot + "只脚");
        calculation(head, foot);
    }
}
